//
//  XZStatusFrame.m
//  XZIBeeBo
//
//  Created by Sean on 16/4/10.
//  Copyright © 2016年 XZSean. All rights reserved.
//
#import "XZStatusFrame.h"
#import "XZStatusModel.h"
#import "XZUserModel.h"
#import "NSString+XZExtension.h"
#import "HWStatusPhotosView.h"

@implementation XZStatusFrame


/**
 *  重写set方法计算frame
 */
-(void)setStatus:(XZStatusModel *)status{

    _status = status;
    
    XZUserModel *user = status.user;
    
    // cell的宽度
    CGFloat cellW = [UIScreen mainScreen].bounds.size.width;

    
    /** 原创微博整体 */

    /** 头像 */
    CGFloat iconWH = 35;
    CGFloat iconX = XZStatusCellBorderW;
    CGFloat iconY = XZStatusCellBorderW;
    self.iconViewF = CGRectMake(iconX, iconY, iconWH, iconWH);
    
   
    /** 昵称 */
    CGFloat nameX = CGRectGetMaxX(self.iconViewF) + XZStatusCellBorderW;
    CGFloat nameY = iconY;
    CGSize nameSize = [user.name sizeWithFont:HWStatusCellNameFont];
//    self.nameLabelF = CGRectMake(nameX, nameY, nameSize.width, nameSize.height);
    self.nameLabelF = (CGRect){{nameX, nameY}, nameSize};

    
    /** 会员图标 */
    if (user.isVip) {
        CGFloat vipX = CGRectGetMaxX(self.nameLabelF) + XZStatusCellBorderW;
        CGFloat vipY = nameY;
        CGFloat vipH = nameSize.height;
        CGFloat vipW = 20;
        self.vipViewF = CGRectMake(vipX, vipY, vipW, vipH);
    }
 
    /** 时间 */
    CGFloat timeX = nameX;
    CGFloat timeY = CGRectGetMaxY(self.nameLabelF) + XZStatusCellBorderW;
    CGSize timeSize = [status.created_at sizeWithFont:HWStatusCellTimeFont];
    self.timeLabelF = CGRectMake(timeX, timeY, timeSize.width, timeSize.height);
    //self.timeLabelF = (CGRect){{timeX, timeY}, timeSize};
   
    /** 来源 */
    CGFloat sourceX = CGRectGetMaxX(self.timeLabelF) + XZStatusCellBorderW;
    CGFloat sourceY = timeY;
    CGSize sourceSize = [status.source sizeWithFont:HWStatusCellSourceFont];
    self.sourceLabelF = (CGRect){{sourceX, sourceY}, sourceSize};
 
    /** 正文 */
    CGFloat contentX = iconX;
    CGFloat contentY = MAX(CGRectGetMaxY(self.iconViewF), CGRectGetMaxY(self.timeLabelF)) + XZStatusCellBorderW;
    CGFloat maxW = cellW - 2 * contentX;
    CGSize contentSize = [status.text sizeWithFont:HWStatusCellContentFont maxW:maxW];
    self.contentLabelF = (CGRect){{contentX, contentY}, contentSize};
    
    
    /** 配图 */
    CGFloat originalH = 0;
    if (status.pic_urls.count) { //有配图
        
        //CGFloat photoWH = 100;
        CGFloat photoX = contentX;
        CGFloat photoY = CGRectGetMaxY(self.contentLabelF) + XZStatusCellBorderW;
        CGSize   photoSize = [HWStatusPhotosView sizeWithCount:status.pic_urls.count];
        
        self.photoViewF = (CGRect){{photoX, photoY}, photoSize};
        
          originalH = CGRectGetMaxY(self.photoViewF) + XZStatusCellBorderW;
    } else { //没有配图
    
          originalH = CGRectGetMaxY(self.contentLabelF) + XZStatusCellBorderW;
    }
   
    
    /** 原创微博整体 */
    CGFloat originalX = 0;
    CGFloat originalY = 15;
    CGFloat originalW = cellW;
   // CGFloat originalH = CGRectGetMaxY(self.contentLabelF) + XZStatusCellBorderW;
    self.originalViewF = CGRectMake(originalX, originalY, originalW, originalH);
   
    
    CGFloat toolBarY= 0;
    
    /* 被转发微博 */
    if (status.retweeted_status) {
        XZStatusModel *retweeted_status = status.retweeted_status;
        XZUserModel *retweeted_status_user = retweeted_status.user;
        
        /** 被转发微博正文 */
        CGFloat retweetContentX = XZStatusCellBorderW;
        CGFloat retweetContentY = XZStatusCellBorderW;
        NSString *retweetContent = [NSString stringWithFormat:@"@ %@ : %@", retweeted_status_user.name, retweeted_status.text];
      
        CGSize retweetContentSize = [retweetContent sizeWithFont:HWStatusCellRetweetContentFont maxW:maxW];
        
        self.retweetcontentLabelF = (CGRect){{retweetContentX, retweetContentY}, retweetContentSize};
       
        /** 被转发微博配图 */
        CGFloat retweetH = 0;
        if (retweeted_status.pic_urls.count) { // 转发微博有配图
         
           // CGFloat retweetPhotoWH = 100;
            CGFloat retweetPhotoX = retweetContentX;
            CGFloat retweetPhotoY = CGRectGetMaxY(self.retweetcontentLabelF) + XZStatusCellBorderW;
            CGSize  retweetPhotoSize = [HWStatusPhotosView sizeWithCount:retweeted_status.pic_urls.count];
            
            self.retweetphotoViewF = (CGRect){{retweetPhotoX, retweetPhotoY}, retweetPhotoSize};
           
            retweetH = CGRectGetMaxY(self.retweetphotoViewF) + XZStatusCellBorderW;
        } else { // 转发微博没有配图
            retweetH = CGRectGetMaxY(self.retweetcontentLabelF) + XZStatusCellBorderW;
        }
     
        /** 被转发微博整体 */
        CGFloat retweetX = 0;
        CGFloat retweetY = CGRectGetMaxY(self.originalViewF);
        CGFloat retweetW = cellW;
        self.retweetViewF = CGRectMake(retweetX, retweetY, retweetW, retweetH);
        
         toolBarY  = CGRectGetMaxY(self.retweetViewF);
    } else {
         toolBarY  = CGRectGetMaxY(self.originalViewF);
    }
    
    
    /** 工具条 */
    CGFloat toolbarX = 0;
    CGFloat toolbarW = cellW;
    CGFloat toolbarH = 35;
    self.toolBarF = CGRectMake(toolbarX, toolBarY, toolbarW, toolbarH);
    
    /* cell的高度 */
    self.cellHeight = CGRectGetMaxY(self.toolBarF);;
  }
@end
